/*
 * sso
 */
package com.opensso.domain.ctrl;

import com.alibaba.fastjson.JSON;
import com.opensso.core.exceptions.BaseException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.opensso.core.entity.BeanRet;
import com.opensso.core.entity.Page;
import com.opensso.core.tools.redis.RedisUtils;
import com.opensso.domain.entity.DomainPool;
import com.opensso.domain.service.DomainPoolSV;

/**
 * 域名池 控制器
 *
 * @author helixin
 */
@RestController
@RequestMapping("/domainPool")
@Slf4j
@Api(value = "域名池控制器", description = "域名池控制器")
public class DomainPoolCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private DomainPoolSV domainPoolSV;

    /**
     * 查询DomainPool一个详情信息
     *
     * @param id   id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询DomainPool一个详情信息", notes = "查询DomainPool一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id, java.lang.String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        DomainPool domainPool = domainPoolSV.load(id, code);
        log.info(JSON.toJSONString(domainPool));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainPool);
    }


    /**
     * 根据条件id查询DomainPool一个详情信息
     *
     * @param id id
     * @return BeanRet
     */
    @ApiOperation(value = "查询DomainPool一个详情信息", notes = "查询DomainPool一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        DomainPool domainPool = domainPoolSV.loadById(id);
        log.info(JSON.toJSONString(domainPool));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainPool);
    }

    /**
     * 根据条件code查询DomainPool一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询DomainPool一个详情信息", notes = "查询DomainPool一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable java.lang.String code) {
        if (code == null) {
            return null;
        }
        DomainPool domainPool = domainPoolSV.loadByCode(code);
        log.info(JSON.toJSONString(domainPool));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainPool);
    }


    /**
     * 查询DomainPool信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询DomainPool信息集合", notes = "查询DomainPool信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "domain", value = "域名", paramType = "query"),
            @ApiImplicitParam(name = "apiKey", value = "apikey 用于验证授权", paramType = "query"),
            @ApiImplicitParam(name = "apiSecret", value = "apiSecret 密码调用设置", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：启用 Enable 禁用 Disable", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "说明 64个汉字", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore DomainPool domainPool, Integer curPage, Integer pageSize) {
        Page<DomainPool> page = new Page<DomainPool>(pageSize, curPage);
        List<DomainPool> domainPools = domainPoolSV.list(domainPool, page.genRowStart(), page.getPageSize());
        int total = domainPoolSV.count(domainPool);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainPools);
    }


    /**
     * 查询DomainPool信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询DomainPool信息集合", notes = "查询DomainPool信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, java.lang.String code, Integer curPage, Integer pageSize) {
        Page<DomainPool> page = new Page<DomainPool>(pageSize, curPage);
        List<DomainPool> domainPools = domainPoolSV.list(id, code, page.genRowStart(), page.getPageSize());
        int total = domainPoolSV.count(id, code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainPools);
    }

    /**
     * 统计DomainPool信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计DomainPool信息数量根据主键", notes = " 统计DomainPool信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String code) {
        return domainPoolSV.count(id, code);
    }

    /**
     * 统计DomainPool信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计DomainPool信息数量", notes = "统计DomainPool信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "domain", value = "域名", paramType = "query"),
            @ApiImplicitParam(name = "apiKey", value = "apikey 用于验证授权", paramType = "query"),
            @ApiImplicitParam(name = "apiSecret", value = "apiSecret 密码调用设置", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：启用 Enable 禁用 Disable", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "说明 64个汉字", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody DomainPool domainPool) {
        if (domainPool == null) {
            return domainPoolSV.count(new HashMap());
        } else {
            return domainPoolSV.count(domainPool);
        }
    }


    /**
     * 创建DomainPool
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建DomainPool", notes = "创建DomainPool")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "domainBegin", value = "域名", paramType = "query"),
            @ApiImplicitParam(name = "domainEnd", value = "域名", paramType = "query"),
            @ApiImplicitParam(name = "apiKeyBegin", value = "apikey 用于验证授权", paramType = "query"),
            @ApiImplicitParam(name = "apiKeyEnd", value = "apikey 用于验证授权", paramType = "query"),
            @ApiImplicitParam(name = "apiSecretBegin", value = "apiSecret 密码调用设置", paramType = "query"),
            @ApiImplicitParam(name = "apiSecretEnd", value = "apiSecret 密码调用设置", paramType = "query"),
            @ApiImplicitParam(name = "stateBegin", value = "状态：启用 Enable 禁用 Disable", paramType = "query"),
            @ApiImplicitParam(name = "stateEnd", value = "状态：启用 Enable 禁用 Disable", paramType = "query"),
            @ApiImplicitParam(name = "summaryBegin", value = "说明 64个汉字", paramType = "query"),
            @ApiImplicitParam(name = "summaryEnd", value = "说明 64个汉字", paramType = "query"),
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore DomainPool domainPool) {
        domainPoolSV.save(domainPool);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainPool);
    }


    /**
     * 修改DomainPool
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改DomainPool", notes = "修改DomainPool")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "domain", value = "域名", paramType = "query"),
            @ApiImplicitParam(name = "apiKey", value = "apikey 用于验证授权", paramType = "query"),
            @ApiImplicitParam(name = "apiSecret", value = "apiSecret 密码调用设置", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：启用 Enable 禁用 Disable", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "说明 64个汉字", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore DomainPool domainPool) {
        domainPoolSV.modify(domainPool);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainPool);
    }

    /**
     * 删除DomainPool
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除DomainPool", notes = "删除DomainPool")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String code) {
        domainPoolSV.delete(id, code);
        return BeanRet.create(true, "删除DomainPool成功");
    }

}
